<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateVenuesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('venues', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('自增ID');

            $table->string('name', 300)->comment('场馆名称');
            $table->string('desc', 300)->nullable()->comment('简介');
            $table->string('image', 500)->comment('图片');
            $table->unsignedTinyInteger('meet_cancel_set')->comment('取消设置 0=不允,1=允许,2=仅开始前可取消');
            $table->unsignedTinyInteger('meet_status')->default(1)->comment('状态 0=未启用,1=使用中,9=停止预约,10=已关闭');
            $table->unsignedInteger('meet_max_join')->default(9999)->comment('预约最大人数');
            $table->string('info', 2000)->comment('场馆信息');
            $table->unsignedBigInteger('publisher_uid')->comment('发布者uid')->index();

            $table->timestamps();
            $table->softDeletes();

            $table->engine = 'InnoDB';
        });

        Schema::create('meet_days', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('自增ID');

            $table->unsignedBigInteger('venue_id')->comment('场馆id')->index();

            $table->timestamp('day')->comment('日期 yyyy-mm-dd');
            $table->string('desc', 300)->nullable()->comment('描述');
            $table->unsignedTinyInteger('status')->default(1)->comment('状态');

            $table->unsignedBigInteger('publisher_uid')->comment('发布者uid')->index();

            $table->timestamps();
            $table->softDeletes();

            $table->engine = 'InnoDB';
        });
        Schema::create('meet_hours', function (Blueprint $table) {
            $table->unsignedBigInteger('meet_hour_id')->comment('唯一ID')->primary();

            $table->unsignedBigInteger('venue_id')->comment('场馆id')->index();
            $table->unsignedBigInteger('meet_day_id')->comment('日期id')->index();

            $table->string('start', 300)->comment('开始时间点hh:mm ～');
            $table->string('end', 300)->comment('结束时间点hh:mm');
            $table->unsignedTinyInteger('is_limit')->default(0)->comment('是否人数限制');
            $table->unsignedInteger('limit')->default(0)->comment('报名上限');
            $table->unsignedTinyInteger('status')->default(1)->comment('状态');

            $table->unsignedBigInteger('publisher_uid')->comment('发布者uid')->index();

            $table->timestamps();
            $table->softDeletes();

            $table->engine = 'InnoDB';
        });

        DB::statement("alter table `venues` comment'场馆表'");
        DB::statement("alter table `meet_days` comment'场馆预约日期表'");
        DB::statement("alter table `meet_hours` comment'场馆预约小时表'");


    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('venues');
    }
}
